<?php
declare (strict_types = 1);

namespace app\listener;

use app\admin\model\user\UserAction;
use think\facade\Cache;

class UserActionListener
{
    /**
     * 事件监听处理
     *
     * @return mixed
     */
    public function handle($event)
    {
        $action = [
            1 => "用户浏览了{$event['keyword']}",
            2 => "用户搜索了{$event['keyword']}",
        ];
        $params['action'] = $action[$event['type']];
        $params['uid'] = $event['uid'];
        $params['price'] = $event['price'];
        $params['keyword'] = $event['keyword'];

        Cache::store('redis')->set("one:ea_user_action:uid-{$params['uid']}:keyword",$params['keyword']);

        UserAction::create($params);
    }
}
